package cn.itcast.service.company.impl;

import cn.itcast.dao.company.CompanyDao;
import cn.itcast.domain.company.Company;
import cn.itcast.service.company.CompanyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * 企业Service实现
 */
@Service
public class CompanyServiceImpl implements CompanyService{

    //注入Dao对象
    @Autowired
    private CompanyDao companyDao;


    @Override
    public List<Company> findAll() {
        return companyDao.findAll();
    }
//修改企业
    @Override
    public void update(Company company) {
        companyDao.update(company);
    }
//添加企业
    @Override
    public void save(Company company) {
        company.setId(UUID.randomUUID().toString());
        companyDao.save(company);
    }
//根据id查企业
    @Override
    public Company findById(String id) {

        return companyDao.findById(id);
    }

    @Override
    public void deleteById(String id) {
        companyDao.deleteById(id);
    }

    @Override
    public PageInfo findByPage(int pageNum, int pageSize) {
        //1.设置分页参数
        PageHelper.startPage(pageNum,pageSize);
        //2.查询所有数据
        List<Company> list = companyDao.findAll();
        //3.封装PageInfo
        return  new PageInfo<>(list);
    }
}
